#!/bin/bash

set -e
set -x

iplist_path=config
i=0
while read -r line
do
    case $line in
        *'#'*)
            continue
        ;;
        *'end'*)
            break
        ;;
        *)
            IFS=',' read -ra parts <<< "$line"
        ;;
    esac
    
    pass="${parts[0]}" 
    address="${parts[1]}"
    hostname="${parts[2]}"
    if [ $address ];then
        sed -i "s/(controller-$i-host)/$hostname/" server.properties.tpl
        let i=i+1
    fi
done < $iplist_path

cluster_id="$(kafka_2.13-3.9.0/bin/kafka-storage.sh random-uuid)"

sed -i "s/(cluster-id)/$cluster_id/" format.sh

set +x
set +e